class Solution:
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if len(strs) == 0:
            return ''

        strs.sort()
        l = len(strs)
        firstStr = strs[0]
        lastStr = strs[l - 1]
        
        newStrs = [lastStr, firstStr]
        minLen = min(map(len, newStrs))

        res = ''
        for i in range(minLen):
            if newStrs[0][i] != newStrs[1][i]:
                return res
            else:
                res += newStrs[0][i]

        return res

s = Solution()
print(s.longestCommonPrefix(["flower","flow","flight"]))
print(s.longestCommonPrefix(["dog","racecar","car"]))
print(min(map(len, ["flower","flow","flights"])))

